<template>
  <view class="ad-banner">
    <swiper
      class="banner-swiper"
      :indicator-dots="banners.length > 1"
      indicator-color="rgba(255, 255, 255, 0.6)"
      indicator-active-color="#FFFFFF"
      autoplay
      interval="3000"
      duration="500"
      circular
    >
      <swiper-item v-for="(item, index) in banners" :key="index" @click="onBannerClick(item)">
        <view class="banner-item" :style="{ backgroundColor: item.bgColor || '#f5f5f5' }">
          <view class="banner-icon">
            <image class="icon-image" :src="getIconPath(item.icon)" mode="aspectFit"></image>
          </view>
          <view class="banner-content" v-if="item.title">
            <text class="banner-title">{{ item.title }}</text>
            <text class="banner-desc" v-if="item.description">{{ item.description }}</text>
          </view>
        </view>
      </swiper-item>
    </swiper>
  </view>
</template>

<script setup>
import { ref, defineProps, defineEmits } from 'vue';

const props = defineProps({
  banners: {
    type: Array,
    default: () => []
  }
});

const emit = defineEmits(['bannerClick']);

const onBannerClick = (item) => {
  emit('bannerClick', item);
};

// 获取图标路径
const getIconPath = (icon) => {
  return `/static/icons/${icon}.png`;
};
</script>

<style lang="scss" scoped>
.ad-banner {
  width: 100%;

  .banner-swiper {
    width: 100%;
    height: 300rpx;
  }

  .banner-item {
    position: relative;
    width: 100%;
    height: 100%;
    border-radius: 16rpx;
    display: flex;
    align-items: center;
    padding: 0 30rpx;

    .banner-icon {
      flex-shrink: 0;
      display: flex;
      justify-content: center;
      align-items: center;
      margin-right: 20rpx;
      
      .icon-image {
        width: 120rpx;
        height: 120rpx;
      }
    }

    .banner-content {
      flex: 1;

      .banner-title {
        font-size: 32rpx;
        color: #333;
        font-weight: bold;
        display: block;
        margin-bottom: 8rpx;
      }

      .banner-desc {
        font-size: 24rpx;
        color: #666;
        display: block;
      }
    }
  }
}
</style>
